new Vue({
  el: '#app',
  data() {
    return {
      form: {
        Row_Status: '',
        Collection_Type: '',
        page: 1,			//页数
        limit: 10			//每页数据条数
      },
      tableData: [],		//表格数据
      total: 1,
    }
  },
  mounted() {
    this.getList(this.form)
  },
  methods: {
    onSerach() {				//查询方法
      console.log("搜搜")
    },
    addContract() {
      console.log("跳转")
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form)
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form)
    },
    getList(data) {     //换页方法
      let _this = this
      $.ajax({
        type: 'POST',
        url: DomainName + "/getprepaymentCardCollectionAction?token=" + $.cookie('token'),
        data,
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        success: function (Result) {
          console.log(Result);
          _this.tableData = Result.tableData      //将获取的数据存到表格数据中
          _this.total = Number(Result.limit)
        },
        dataType: "json"
      });
    },
    handle(row){//收款确认
      if(row.Row_Status=='0'&&row.Collection_Type=='现金'){
        this.$confirm('该订单确认后将发放储值卡，是否已收款?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          $.ajax({
            type: 'POST',
            url: DomainName + "/CashPaymentRechargeCardAction?token=" + $.cookie('token'),
            data:{ Collection_SerialNumber:row.Collection_SerialNumber },
            complete:(XMLHttpRequest)=> {
              if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
              }
            },
            error: ()=> {
              this.$message({
                type: 'error',
                message: '系统错误！请联系开发者'
              });
            },
            success: (Result)=> {
              if(Result.Status == 'success'){
                this.$message({
                  type: 'success',
                  message: '确认成功！已发放储值卡'
                });
                this.getList(this.form)
              }
            },
            dataType: "json"
          });
        }).catch(() => {
          this.$message({
            type: 'warning',
            message: '已取消'
          });
        });
      }
    }
  },
})